<template>
	<view class="content">
		<view class="layout">
			<view class="box" v-for="(item,index) in arrs" :key="item._id">
				<view class="pic">
					<image :src="item.url" mode="widthFix" @click="preView(index)"></image>
				</view>
				<view class="text">{{item.content}}</view>
				<view class="author">--{{item.author}}</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import {ref} from 'vue'
const arrs = ref([]);

//图片预览
const preView = function(index){
	let urls = arrs.value.map(item => item.url);
	uni.previewImage({
		current:index,  //图片下标
		urls: urls
	})
}

//获取数据
function getData(){
	uni.request({
		url:'https://tea.qingnian8.com/tools/petShow',
		data:{
			size:5
		}
	}).then((res)=>{
		if(res.data.errCode === 0){
			//成功获取
			arrs.value = res.data.data;
		}else if(res.data.errCode === 400){
			uni.showToast({
				title:'接口错误'
			})
		}
	}).catch(err=>{
		
	}).finally(()=>{
		
	})
}
getData();

</script>

<style lang="scss">
	.content {
		.layout{
			padding: 50rpx;
			.box{
				margin-bottom: 60rpx;
				border-radius: 20rpx;
				box-shadow: 0 10rpx 30rpx rgba(0,0,0,0.09);
				.pic{
					image{
						width: 100%;
					}
				}
				.text{
					padding: 30rpx 0 30rpx 0;
					font-size: 36rpx;
					color: #969696;
				}
				.author{
					padding-bottom: 30rpx;
					padding-right: 10rpx;
					text-align: right;
					font-size: 24rpx;
					color:#bebebe;
				}
			}
		}
	}

	
</style>
